package com.bocai.freeman.view.activitys;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TableRow;

import com.bocai.freeman.R;
import com.bocai.freeman.base.BaseActivity;
import com.bocai.freeman.model.bean.EventMessage;
import com.bocai.freeman.utils.ToolbarHelper;
import com.bocai.freeman.view.adapter.PersonCenterAdapter;
import com.bocai.freeman.view.custom.MRatingBar;
import com.bocai.freeman.view.custom.NoScrollListView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by win7 on 2016/5/24.
 */
public class PersonCenterActivity extends BaseActivity {
    @Bind(R.id.lv_no)
    NoScrollListView lvNo;
    @Bind(R.id.rvice_start)
    MRatingBar rviceStart;
    @Bind(R.id.tr_identity_authent)
    TableRow trIdentityAuthent;
    @Bind(R.id.img_attestation)
    ImageView imgAttestation;
    @Bind(R.id.tr_person_data)
    TableRow trPersonData;
    @Bind(R.id.ll_person_dynamic)
    LinearLayout llPersonDynamic;
    @Bind(R.id.tr_more_evaluate)
    TableRow trMoreEvaluate;
    @Bind(R.id.btn_usercp)
    Button btnUsercp;
    @Bind(R.id.btn_xinyu)
    Button btnXinyu;
    @Bind(R.id.btn_talk)
    Button btnTalk;
    @Bind(R.id.btn_attention)
    Button btnAttention;
    @Bind(R.id.btn_blacklist)
    Button btnBlacklist;

    private PersonCenterAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_person_center);
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
        ToolbarHelper.setup(this, getString(R.string.str_person_center), R.mipmap.left_return, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        initView();
        initEvent();
    }


    @Override
    protected void initView() {
        imgAttestation.setVisibility(View.GONE);
        lvNo.setFocusable(false);
        mAdapter = new PersonCenterAdapter(this);
        lvNo.setAdapter(mAdapter);

    }

    @Subscribe
    public void event(EventMessage eventMessage) {
        if (eventMessage.message.equals("buySkill")) {
            startActivity(new Intent(this, LaunchOrderActivity.class));

        } else if (eventMessage.message.equals("contact")) {
            showToast("contact");

        }
    }

    @Override
    protected void initEvent() {
        click(trPersonData).subscribe(o -> {
            Intent intent = new Intent(new Intent(this, PersonDataActivity.class));
            intent.putExtra("type", "editGone");
            startActivity(intent);
        });
        click(llPersonDynamic).subscribe(o -> {
            Intent intent = new Intent(this, PerfectLightActivity.class);
            intent.putExtra("title", getString(R.string.str_friends_dynamic));
            startActivity(intent);
        });
        click(trMoreEvaluate).subscribe(o -> startActivity(new Intent(this, MoreEvaluateActivity.class)));
        click(btnUsercp).subscribe(o -> showToast("魅力值"));
        click(btnXinyu).subscribe(o -> showToast("信誉值"));
        click(btnTalk).subscribe(o -> showToast("对话"));
        click(btnAttention).subscribe(o -> showToast("关注"));
        click(btnBlacklist).subscribe(o -> showToast("黑名单"));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
